package com.fgw.admin.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.fgw.admin.dto.ResultInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;

import com.fgw.admin.entity.Dept;
import com.fgw.admin.service.IDeptService;

/**
 *  前端控制器
 *
 * @author system
 * @date 2020-11-16 21:02:15
 */
@Controller
@RequestMapping("/dept")
public class DeptController {
    @Resource
    private IDeptService iDeptService;

    @RequestMapping("/*")
    public void toHtml(){

    }

    @RequestMapping("/listData")
    @RequiresPermissions("dept:view")
    public @ResponseBody
    ResultInfo<List<Dept>> listData(Dept dept,@RequestParam(defaultValue="1") Integer page,@RequestParam(defaultValue="10") Integer limit){
        EntityWrapper<Dept> wrapper = new EntityWrapper<>(dept);
        Page<Dept> pageObj = iDeptService.selectPage(new Page<>(page,limit), wrapper);
        return new ResultInfo<>(pageObj.getRecords(), pageObj.getTotal());
    }

    @RequestMapping("/add")
    @RequiresPermissions("dept:add")
    public @ResponseBody
    ResultInfo<Boolean> add(Dept dept){
        boolean b = iDeptService.insert(dept);
        return new ResultInfo<>(b);
    }

    @RequestMapping("/delBatch")
    @RequiresPermissions("dept:del")
    public @ResponseBody
    ResultInfo<Boolean> delBatch(Integer[] idArr){
        boolean b = iDeptService.deleteBatchIds(Arrays.asList(idArr));
        return new ResultInfo<>(b);
    }

    @RequestMapping("/edit")
    @RequiresPermissions("dept:edit")
    public @ResponseBody
    ResultInfo<Boolean> edit(Dept dept){
        boolean b = iDeptService.updateById(dept);
        return new ResultInfo<>(b);
    }

}
